package com.changgou.service.goods.controller;

import com.changgou.common.pojo.Result;
import com.changgou.common.pojo.StatusCode;
import com.changgou.goods.pojo.Goods;
import com.changgou.service.goods.service.SpuService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("spu")
public class SpuController {

    @Resource
    private SpuService spuService;

    /***
     * 新增数据
     */
    @PostMapping
    public Result<String> add(@RequestBody Goods goods) {
        spuService.add(goods);
        return new Result<String>(true, StatusCode.OK, "添加成功");
    }

    @GetMapping("/{id}")
    public Result<Goods> findById(@PathVariable String id) {
        Goods goods = spuService.findGoodsById(id);
        return new Result<Goods>(true, StatusCode.OK, "查询成功", goods);
    }

    /***
     * 修改数据
     */
    @PutMapping(value = "/{id}")
    public Result<String> update(@RequestBody Goods goods, @PathVariable String id) {
        spuService.update(goods);
        return new Result<String>(true, StatusCode.OK, "修改成功");
    }

    /**
     * 审核
     */
    @PutMapping("/audit/{id}")
    public Result<Void> audit(@PathVariable String id) {
        spuService.audit(id);
        return new Result<Void>();
    }

    /**
     * 下架
     */
    @PutMapping("/pull/{id}")
    public Result<Void> pull(@PathVariable String id) {
        spuService.pull(id);
        return new Result<Void>();
    }

    /**
     * 上架
     */
    @PutMapping("/put/{id}")
    public Result<Void> put(@PathVariable String id) {
        spuService.put(id);
        return new Result<Void>();
    }

    //删除
    @DeleteMapping("delete/{id}")
    public Result<Void> delete(@PathVariable String id) {
        spuService.delete(id);
        return new Result<Void>();
    }
    //删除
    @DeleteMapping("delete/{id}")
    public Result<Void> restore(@PathVariable String id) {
        spuService.restore(id);
        return new Result<Void>();
    }

    /**
     * 物理删除
     */
    @DeleteMapping("/realDelete/{id}")
    public Result<Void> realDelete(@PathVariable String id){
        spuService.realDelete(id);
        return new Result<Void>();
    }
}
